#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define max 10
#define duichang 100

typedef struct MG
{
	char v[max];
	int a[max][max];
	int vn,an;
}mg;
int geti(mg * g,char c)
{
	int i;
	for(i=0;i<g->vn ;i++){
		if(g->v [i]==c)
			return i;
	}
}
void cre_g(mg * g)
{
	scanf("%d%d",&g->vn,&g->an );
	int i;
	for(i=0;i<g->vn ;i++){
		scanf(" %c",&g->v [i]);
	}

	int j;
	for(i=0;i<g->vn ;i++)
		for(j=0;j<g->vn ;j++)
			g->a [i][j]=0;
	int k,w;
	char st,end;
	for(k=0;k<g->an ;k++){
		scanf(" %c %c %d",&st,&end,&w);
		i=geti(g,st);
		j=geti(g,end);
		g->a [i][j]=w;
		g->a [j][i]=w;
	}
}